import logging

from fastapi import APIRouter, Depends

from {{{ package_name }}}.schema_base import PageInationResult
from {{{ package_name }}}.http_base import unified_resp
from ..schemas.{{{entity_snake_name}}} import (
    {{{ entity_name }}}ListIn, {{{ entity_name }}}DetailIn, {{{ entity_name }}}AddIn, 
    {{{ entity_name }}}EditIn, {{{ entity_name }}}DelIn, {{{ entity_name }}}Out)
from ..service.{{{module_name}}}.{{{entity_snake_name}}} import I{{{ entity_name }}}Service

logger = logging.getLogger(__name__)

router = APIRouter(prefix='/{{{ module_name }}}/{{{entity_snake_name}}}')


@router.post('/list'{% if table.gen_tpl == 'crud' %}, response_model=PageInationResult[{{{ entity_name }}}Out]{% endif %}, summary='{{{ function_name }}}列表')
@unified_resp
async def {{{ entity_snake_name }}}_list(
        list_in: {{{ entity_name }}}ListIn,
        {{{ entity_snake_name }}}_service: I{{{ entity_name }}}Service = Depends()):
    """{{{ function_name }}}列表"""
    return await {{{ entity_snake_name }}}_service.list(list_in)


@router.get('/detail', summary='{{{ function_name }}}详情')
@unified_resp
async def {{{ entity_snake_name }}}_detail(
        detail_in: {{{ entity_name }}}DetailIn = Depends(),
        {{{ entity_snake_name }}}_service: I{{{ entity_name }}}Service = Depends()):
    """{{{ function_name }}}详情"""
    return await {{{ entity_snake_name }}}_service.detail(detail_in.id)


@router.post('/add', summary='{{{ function_name }}}新增')
@unified_resp
async def {{{ entity_snake_name }}}_add(
        add_in: {{{ entity_name }}}AddIn,
        {{{ entity_snake_name }}}_service: I{{{ entity_name }}}Service = Depends()):
    """{{{ function_name }}}新增"""
    return await {{{ entity_snake_name }}}_service.add(add_in)


@router.post('/edit', summary='{{{ function_name }}}编辑')
@unified_resp
async def {{{ entity_snake_name }}}_edit(
        edit_in: {{{ entity_name }}}EditIn,
        {{{ entity_snake_name }}}_service: I{{{ entity_name }}}Service = Depends()):
    """{{{ function_name }}}编辑"""
    return await {{{ entity_snake_name }}}_service.edit(edit_in)


@router.post('/del', summary='{{{ function_name }}}删除')
@unified_resp
async def {{{ entity_snake_name }}}_del(
        del_in: {{{ entity_name }}}DelIn,
        {{{ entity_snake_name }}}_service: I{{{ entity_name }}}Service = Depends()):
    """{{{ function_name }}}删除"""
    return await {{{ entity_snake_name }}}_service.delete(del_in.id)

{% if table.is_basic_data %}

@router.post('/all',include_in_schema=False, summary='{{{ function_name }}}全部')
@unified_resp
async def {{{ entity_snake_name }}}_all(all_in: {{{ entity_name }}}ListIn, service: I{{{ entity_name }}}Service = Depends()):
    return await service.all(all_in)
{% endif %}